package com.common.frame.widget

import android.content.Context
import android.os.Build
import android.util.AttributeSet

import androidx.appcompat.widget.AppCompatImageView
import com.common.frame.R
import com.zhpan.bannerview.provider.ViewStyleSetter

class CornerImageView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr) {

    var radius = 0

    init {

        if (attrs != null) {
            val typedArray =
                getContext().obtainStyledAttributes(attrs, R.styleable.CornerImageView)
             radius = typedArray.getLayoutDimension(R.styleable.CornerImageView_corner_radius, 0)
            typedArray.recycle()
        }
        if (radius != 0) {
            setRoundCorner(radius)
        }

    }
    fun setRoundCorner(radius: Int) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ViewStyleSetter.applyRoundCorner(this, radius.toFloat())
        }
    }
}